import 'package:flutter/material.dart';

class TextFieldPage extends StatefulWidget {
  @override
  _TextFieldPageState createState() => _TextFieldPageState();
}

class _TextFieldPageState extends State<TextFieldPage> {
  var username = TextEditingController(); // 当设置初始值得时候设置这个
  String password;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    this.username.text='初始值';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TextField'),
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: ListView(
          children: <Widget>[
            TextField(
              controller: this.username,
              decoration: InputDecoration(
                hintText: '用户名'
              ),
            ),
            TextField(
              obscureText: true,
              decoration: InputDecoration(
                 hintText: '密码'
              ),
              onChanged: (value) {
                this.password = value;
              },
            ),
            RaisedButton(
              child: Text('获取输入框的值'),
              onPressed: () {
                print('用户名:${this.username.text}，密码:${this.password}');
              },
            ),
            SizedBox(
              height: 20,
            ),
            TextField(
              decoration: InputDecoration(
                  hintText: '请输入内容', border: OutlineInputBorder()),
            ),
            SizedBox(
              height: 20,
            ),
            TextField(
              maxLines: 4,
              maxLength: 10,
              decoration: InputDecoration(
                  hintText: '多行文本框', border: OutlineInputBorder()),
            ),
            SizedBox(
              height: 20,
            ),
            TextField(
              obscureText: true,
              decoration: InputDecoration(
                  hintText: '密码输入框', border: OutlineInputBorder()),
            ),
            SizedBox(
              height: 20,
            ),
            TextField(
              decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: '浮动label'),
            ),
            SizedBox(
              height: 20,
            ),
            TextField(
              decoration: InputDecoration(
                  hintText:'加图标',
                  icon: Icon(Icons.phone),
            ))
          ],
        ),
      ),
    );
  }
}
